import { ApiProperty } from '@nestjs/swagger';
import { IsInt, IsString } from 'class-validator';
import {
  Column,
  CreateDateColumn,
  Entity,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';

@Entity()
export class Article {
  @ApiProperty({ description: 'id' })
  @IsInt()
  @PrimaryGeneratedColumn()
  id: number;

  @ApiProperty({ description: '标题' })
  @IsString()
  @Column()
  name: string;

  @ApiProperty({
    description:
      '内容, json字符串, 包含多个段落, 每个段落包含中文、英文、拼音、音频(路径、大小b、时长s)等',
    default:
      '[{"content": "中文", "enContent": "英文", "pinyin": ["拼音"], "audio": { "path": "音频路径", "size": 200,  "duration": 10}}]',
  })
  @IsString()
  @Column()
  content: string;

  @ApiProperty({ description: '合辑id' })
  @IsInt()
  @Column()
  gatherId: number;

  @ApiProperty({ description: '浏览需要的vip等级' })
  @IsInt()
  @Column({ type: 'smallint', nullable: false, default: 0 })
  vipLevel: number;

  @ApiProperty({ description: '序号' })
  @IsInt()
  @Column()
  sortOrder: number;

  @ApiProperty({ description: '英文标题' })
  @IsString()
  @Column()
  enName: string;

  @ApiProperty({ description: '标题拼音' })
  @IsString()
  @Column()
  pinyinName: string;

  @ApiProperty({ description: '内容总大小，单位B' })
  @IsInt()
  @Column({ nullable: false, default: 0 })
  size: number;

  @ApiProperty({ description: '内容总时长，单位秒' })
  @IsInt()
  @Column()
  duration: number;

  // @ApiProperty({ description: '文章数量' })
  // @ManyToOne(() => Gather, (gather: Gather) => gather.articles)
  // gather: Gather[];

  @ApiProperty()
  @CreateDateColumn({ type: 'timestamptz', default: () => 'CURRENT_TIMESTAMP' })
  createdAt: string;

  @ApiProperty()
  @UpdateDateColumn({
    type: 'timestamptz',
    default: () => 'CURRENT_TIMESTAMP',
    onUpdate: 'CURRENT_TIMESTAMP',
  })
  updatedAt: string;
}
